package com.stark.commons.spring.core.boot;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.ComponentScan.Filter;

import com.stark.commons.spring.core.aspect.JobMonitor;
import com.stark.commons.spring.core.context.ApplicationContextUtil;
import com.stark.commons.spring.core.support.cache.CacheService;
import com.stark.commons.spring.core.support.cache.EhcacheService;

/**
 * Spring Boot 自动配置。
 * @author Ben
 * @since 1.0.0
 * @version 1.0.0
 */
@Configuration
@ComponentScan(basePackages = "com.stark.commons.spring.core",
	excludeFilters = {
		@Filter(type = FilterType.ANNOTATION, value = Configuration.class)
	}
)
public class AutoConfiguration {
	
	@Bean
    @Lazy(false)
	public ApplicationContextUtil applicationContextUtil() {
		return new ApplicationContextUtil();
	}
	
	@Bean
	public JobMonitor jobMonitor() {
		return new JobMonitor();
	}
	
	@Configuration
	@ConditionalOnClass(name = { "net.sf.ehcache.Cache", "org.springframework.cache.ehcache.EhCacheCacheManager" })
	protected static class EhcacheConfig {
		
		@Bean
		public CacheService cacheService(EhCacheCacheManager ehcacheManager) {
			return new EhcacheService(ehcacheManager);
		}
		
	}

}
